﻿var clients = [];
$(function () {
    clients = $.clientsInit();
})
$.clientsInit = function () {
    var dataJson = {
        dataItems: [],
        organize: [],
        role: [],
        duty: [],
        user: [],
        authorizeMenu: [],
        authorizeButton: []
    };
    var init = function () {
        $.ajax({
            url: "/ClientsData/GetClientsDataJson",
            type: "get",
            dataType: "json",
            async: false,
            success: function (data) {
                dataJson.dataItems = data.dataItems;
                dataJson.organize = data.organize;
                dataJson.role = data.role;
                dataJson.duty = data.duty;
                dataJson.authorizeMenu = eval(data.authorizeMenu);
                dataJson.authorizeButton = data.authorizeButton;
                
                initTodo(dataJson.authorizeMenu);
            }
        });

        
    }
    var initTodo = function (authorizeMenu) {
        // 我的任务中的 动态提示
        $.ajax({
            url: "/OrderFlowManage/ClientOrder/GetCheckRecordTodoJson?pageType=self",
            data: { pageType: "self" },
            dataType: "json",
            async: false,
            success: function (todos) {
                var num = 0;
                for (var i = 0; i < todos.length; i++) {
                    var item = todos[i];
                    if (item.IsTag) {
                        num++;
                    }
                }
                
                if (num > 0) {
                    var ids = ['e0022b50-6f34-40aa-8431-687f155bac65', '882f3373-ce18-459d-aeed-c1e8ab164652'];
                    for (var i = 0; i < authorizeMenu.length; i++) {
                        var item = authorizeMenu[i];
                        for (var j = 0; j < item.ChildNodes.length; j++) {
                            var child = item.ChildNodes[j];
                            if (ids.indexOf(child.F_Id) != -1) {
                                item.ChildNodes[j].F_Icon = 'fa fa-star-o';
                            } else {
                                item.ChildNodes[j].F_Icon = null;
                            }
                        }
                    }
                }
                //console.log(dataJson.authorizeMenu);
                //console.log(authorizeMenu);
            }
        });
    }
    init();
    return dataJson;
}